package com.zulu.karaoke.utils;

import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;

import com.zulu.karaoke.R;
import com.zulu.karaoke.adapter.ListSongAdapter;
import com.zulu.karaoke.database.SongTableHelper;
import com.zulu.karaoke.gui.custom.CustomAlertDialog;
import com.zulu.karaoke.model.SongModel;

public class GeneralUtils {

	public static void showToastAddFavouriteDone(Context context) {
		Toast.makeText(context,
				context.getString(R.string.mess_add_favourite_done),
				Toast.LENGTH_SHORT).show();
	}
	
	public static void showToastRemoveFavouriteDone(Context context) {
		Toast.makeText(context,
				context.getString(R.string.mess_remove_favourite_done),
				Toast.LENGTH_SHORT).show();
	}
	
	public static void showToastMessage(Context context, String mess) {
		Toast.makeText(context, mess, Toast.LENGTH_SHORT).show();
	}
	
	public static void showToastMessageLongTime(Context context, String mess) {
		Toast.makeText(context, mess, Toast.LENGTH_LONG).show();
	}
	
	public static void showPopupSongDetail(final Context context, final SongTableHelper insSongHelper,
			List<String> lstNumber, int position, final ListSongAdapter adapter) {

		final SongModel song = insSongHelper.getSongObjectBaseNumber(lstNumber
				.get(position));
		final View childView = LayoutInflater.from(context).inflate(
				R.layout.song_details_dialog, null, false);

		TextView tvSongNumber = (TextView) childView
				.findViewById(R.id.tv_song_number);
		TextView tvSongTitle = (TextView) childView
				.findViewById(R.id.tv_song_title);
		TextView tvSongBegin = (TextView) childView
				.findViewById(R.id.tv_song_begin);
		TextView tvSongComposer = (TextView) childView
				.findViewById(R.id.tv_song_composer);
		TextView tvSongAlbum = (TextView) childView
				.findViewById(R.id.tv_song_album);
		
		tvSongNumber.setText(song.getSongNumber());
		tvSongTitle.setText(song.getSongTitle());
		tvSongBegin.setText(song.getSongBegin());
		tvSongComposer.setText(song.getSongComposer());
		tvSongAlbum.setText(song.getSongCategory());
		
		Log.i("ListSong", song.getSongNumber());

		final CustomAlertDialog alert = new CustomAlertDialog(context,
				childView, true);

		alert.setTitle(context.getString(R.string.title_song_info));

		if (null == song.getSongFavourite()
				|| song.getSongFavourite().equals("0")) {
			alert.setButton(
					context.getString(R.string.button_text_add_favourite),
					new OnClickListener() {

						@Override
						public void onClick(View arg0) {
							
							song.setSongFavourite("1");
							insSongHelper.updateSong(song);
							adapter.notifyDataSetChanged();
							GeneralUtils.showToastAddFavouriteDone(context);
							alert.hideDialog();
//							refreshAdapterList();
//							adapter.notifyDataSetChanged();
						}
					});
		} else {
			alert.setButton(
					context.getString(R.string.button_text_remove_favourite),
					new OnClickListener() {

						@Override
						public void onClick(View arg0) {
							
							song.setSongFavourite("0");
							insSongHelper.updateSong(song);
							adapter.notifyDataSetChanged();
							GeneralUtils.showToastRemoveFavouriteDone(context);
							alert.hideDialog();
//							refreshAdapterList();
//							adapter.notifyDataSetChanged();
						}
					});
		}

		alert.setButton2(context.getString(R.string.button_text_cancel),
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						
						alert.hideDialog();
					}
				});
		alert.setButton3(context.getString(R.string.button_text_listen_demo), new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				GeneralUtils.showToastMessage(context, "ListenDemo: Pro version only!");
			}
		});
		alert.setButton4(context.getString(R.string.button_text_set_phone_ring), new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				GeneralUtils.showToastMessage(context, "SetPhoneRing: Pro version only!");
			}
		});
		alert.showDialog();
	}
	
//	public static void showPopupFavoriteSongDetail(final Context context, final SongTableHelper insSongHelper,
//			int position, final ListFavouriteAdapter adapter,
//			final FragmentFullListFavourite host, final String[] getListFavoriteNumber, final String[] getListFavoriteTitle,
//			final ListView mLstViewFavourite, final List<String> lstTitle, final List<String> lstNumber) {
//
//		final SongModel song = insSongHelper
//				.getSongObjectBaseNumber(lstNumber.get(position));
//		final View childView = LayoutInflater.from(context)
//				.inflate(R.layout.song_details_dialog, null, false);
//
//		TextView tvSongNumber = (TextView) childView
//				.findViewById(R.id.tv_song_number);
//		TextView tvSongTitle = (TextView) childView
//				.findViewById(R.id.tv_song_title);
//		TextView tvSongBegin = (TextView) childView
//				.findViewById(R.id.tv_song_begin);
//		TextView tvSongComposer = (TextView) childView
//				.findViewById(R.id.tv_song_composer);
//		TextView tvSongAlbum = (TextView) childView
//				.findViewById(R.id.tv_song_album);
//		tvSongNumber.setText(song.getSongNumber());
//		tvSongTitle.setText(song.getSongTitle());
//		tvSongBegin.setText(song.getSongBegin());
//		tvSongComposer.setText(song.getSongComposer());
//		tvSongAlbum.setText(song.getSongCategory());
////		Log.i(TAG, song.getSongNumber());
//
//		final CustomAlertDialog alert = new CustomAlertDialog(
//				context, childView, true);
//
//		alert.setTitle(context
//				.getString(R.string.title_song_info));
//
//		alert.setButton(context.getString(
//						R.string.button_text_remove_favourite),
//				new OnClickListener() {
//
//					@Override
//					public void onClick(View arg0) {
//						song.setSongFavourite("0");
//						insSongHelper.updateSong(song);
//						GeneralUtils
//								.showToastRemoveFavouriteDone(context);
//						alert.hideDialog();
//						GeneralUtils.refreshListView(host, context, adapter, 
//								getListFavoriteNumber, getListFavoriteTitle, mLstViewFavourite, lstTitle, lstNumber);
//					}
//				});
//
//		alert.setButton2(
//				context.getString(R.string.button_text_cancel),
//				new OnClickListener() {
//
//					@Override
//					public void onClick(View v) {
//						alert.hideDialog();
//					}
//				});
//		alert.showDialog();
//	}
//	
//	public static void refreshListView(FragmentFullListFavourite host, Context context, ListFavouriteAdapter adapter, 
//			String[] getListFavoriteNumber, String[] getListFavoriteTitle, 
//			ListView mLstViewFavourite, List<String> lstTitle, List<String> lstNumber) {
//		adapter = new ListFavouriteAdapter(context, getListFavoriteNumber,
//				getListFavoriteTitle);
//		adapter.setNotifyOnChange(true);
//		mLstViewFavourite.setAdapter(adapter);
//		mLstViewFavourite.setOnItemLongClickListener(new ActionModeHelper(host, mLstViewFavourite, lstTitle, lstNumber));
//	}
	
}
